package com.shen.demo.demos.web.tool;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.shen.demo.demos.web.domain.entry.UserName;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

public class JSONResult {
    public static JSONObject convertToJsonObject(List<UserName> userNames, String operationType) {
        ObjectMapper objectMapper = new ObjectMapper();
        /*// 将 List<UserName> 转换为 JSON 字符串
        String jsonList = objectMapper.writeValueAsString(userNames);

        // 将 JSON 字符串转换为 JSONArray
        JSONArray jsonArray = new JSONArray(Collections.singletonList(jsonList));*/

        // 创建最终的 JSONObject
        JSONObject result = new JSONObject();
        result.put("code", 200);
        result.put("data", userNames);
        result.put("message", operationType);
        return result;
    }
}
